using System;
using System.Collections.Generic;
using System.Text;

namespace RapidHDL.Fabric
{
    public class RAMBlock : Block 
    {
        int iWidth;
        bool bRisingEdge;
        int iDepth;

        public RAMBlock(string psName, int piWidth, int piDepth, bool pbRisingEdge)
            : base(psName,"RAM")
        {
            iWidth = piWidth;
            iDepth = piDepth;
            bRisingEdge = pbRisingEdge;
            this.CreateInput("DATA_IN", piWidth);
            this.CreateInput("ADDRESS", Conversion.MinBitWidth(piDepth)); 
            this.CreateOutput("DATA_OUT", piWidth);
            this.CreateControlInput("WRITE");
            //this.CreateControlInput("READ");
        }

        internal override void GenerateStructure()
        {
            RAM oRam = new RAM(ParentComponent, "ram_" + sName, Clock, iWidth, iDepth, bRisingEdge);

            Inputs["DATA_IN"].LinkNodeVector(oRam.I_DATA);
            Inputs["ADDRESS"].LinkNodeVector(oRam.I_ADDRESS);
            Outputs["DATA_OUT"].LinkNodeVector(oRam.O_DATA);
            oRam.I_ENABLE.Join(1);
            ControlInputs["WRITE"].LinkNodeVector(oRam.I_WRITE);
            //ControlInputs["READ"].LinkNodeVector(oRam.I_READ);
            oRam.I_READ.Join(1);
        } 

    }
}
